//
//  LoveListenCollectionViewCellOfContentViewThird.m
//  XYFMApp
//
//  Created by 岁变 on 16/9/19.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "LoveListenCollectionViewCellOfContentViewThird.h"
#import "XYMacro.h"

@interface LoveListenCollectionViewCellOfContentViewThird () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) BaseTableView *tableView;
@property (nonatomic, strong) UIView *customSetUpView;

@end

@implementation LoveListenCollectionViewCellOfContentViewThird

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCustomSetUpView];
        [self createContentTableView];
        //[self createNullImageView];
    }
    return self;
}

//- (void)createNullImageView {
//    
//    _nullImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"download_nologin"]];
//    _nullImageView.backgroundColor = BACKGROUNDCOLOR;
//    _nullImageView.frame = CGRectMake(0, 0, 200, 400);
//    _nullImageView.center = self.contentView.center;
//    [self.contentView addSubview:_nullImageView];
//    _nullImageView.hidden = YES;
//
//}


- (void)createCustomSetUpView {
    
    _customSetUpView = [[UIView alloc] initWithFrame:CGRectZero];
    _customSetUpView.backgroundColor = [UIColor colorWithRed:0.12 green:0.14 blue:0.15 alpha:1.00];
    [self.contentView addSubview:_customSetUpView];
    [_customSetUpView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.height.mas_offset(40);
    }];
}

- (void)createContentTableView {
    _tableView = [[BaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerClass:[LoveListenTableViewCellSecond class] forCellReuseIdentifier:@"LoveListenTableViewCellSecond"];
    [self.contentView addSubview:_tableView];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(40);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
    }];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _model.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LoveListenTableViewCellSecond *cell = [tableView dequeueReusableCellWithIdentifier:@"LoveListenTableViewCellSecond" forIndexPath:indexPath];
    LoveListenModelSecondData *model = [_model.data objectAtIndex:indexPath.row];
    cell.model = model;
    cell.myIndexPath = indexPath;
    cell.modelArr = (NSMutableArray *) _model.data;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    VCOfPlay *nextVC = [VCOfPlay sharePlayVC];
    VCOfLoveListen *currentVC = (VCOfLoveListen *)self.nextResponder.nextResponder.nextResponder;

    
    LoveListenModelSecondData *model = [_model.data objectAtIndex:indexPath.row];
    
    nextVC.mp3URL = model.music_media;
    nextVC.index = indexPath.row;
    nextVC.imagePicURL = model.music_img;
    
    NSMutableArray *mArr = [NSMutableArray array];
    for (LoveListenModelSecondData *model in _model.data) {
        NSString *str = model.music_media;
        [mArr addObject:str];
    }
    nextVC.mp3URLArr = mArr;
    
    nextVC.titleStr = model.music_title;
    NSString *content_id = [NSString stringWithFormat:@"%ld", model.music_id];
    nextVC.content_id = content_id;
    
    [currentVC.navigationController pushViewController:nextVC animated:YES];


}

- (void)setModel:(LoveListenModelSecond *)model {
    
    _model = [[LoveListenModelSecond alloc] init];
    _model = model;
    [_tableView reloadData];
}



@end
